<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <title>点标记添加点击事件</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <style>
        body,
        html,
        #container {
            overflow: hidden;
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
    <!-- <script type="text/javascript" src="http://api.map.baidu.com/api?type=webgl&v=1.0&ak=NoSKBCuXgwAEnhmw9o1iG2O5UdithAw1"></script> -->
    <script type="text/javascript"
        src="http://api.map.baidu.com/api?v=2.0&ak=zTfzuHSdcFvM91GDGujaI4aiyr08gyBZ"></script>
    <script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <!-- <link id="markerIcon" rel="markerIcon" type="image/png" href=""/> -->
</head>

<body>
    <div id="container"></div>
</body>

</html>
<script>
    var map = new BMap.Map('container');
    getRestaurantInfo();

    function addPoint (data) {
        var point = new BMap.Point(data.LNG, data.LAT);
        map.centerAndZoom(point, 15);
        var myIcon = new BMap.Icon('./src/assets/img/warning-mark.png', new BMap.Size(32, 32));
        var marker = new BMap.Marker(point, { icon: myIcon });
        map.addOverlay(marker);
        // 创建信息窗口
        var opts = {
            width: 200,
            height: 100,
            title: '报警信息'
        };
        var str = `<p style="margin-top: 8px;">姓名：${data.环卫工}</p>
      <p style="">报警类型：${data.报警类型}</p>`

        if (data.报警类型 == '超速报警') {
            str += `<p style="">超速时速：${data.报警值}</p>`
        }
        if (data.报警类型 == '滞留报警') {
            str += `<p style="">当前滞留${data.报警值}分钟</p>`
        }
        var infoWindow = new BMap.InfoWindow(str, opts);
        // 开启信息窗口
        map.openInfoWindow(infoWindow, point);
    }
    function getRestaurantInfo () {
        let url = 'http://192.168.1.113:8000/CompanyapiBDEapi/Vehicle/GetSendAlarmInfo?type=人工&id=' + GetQueryValue("id")
        console.log(url)
        $.ajax({
            url: url, success: function (result) {
                console.log(result)
                if (result.length > 0) {
                    addPoint(result[0])
                } else {
                    alert('未查询到报警信息')
                }
            }
        });
    }
    function GetQueryValue (queryName) {
        var reg = new RegExp("(^|&)" + queryName + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return decodeURI(r[2]);
        } else {
            return null;
        }
    }

</script>